package com.xiaoxi.open.design.behavioral.chainofresponsibilitypattern.service.password;

import com.xiaoxi.open.design.behavioral.chainofresponsibilitypattern.domain.password.CheckResult;
import org.springframework.stereotype.Component;

/**
 * @ClassName SpecialCharCheck
 * @Description
 * @Author xiaoxi
 * @Date 2022/7/11 21:36
 * @Version 1.0
 */
@Component
public class SpecialCharCheck extends AbstractCheckPassword {

    public static String SPECIAL_CHAR = "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~";

    @Override
    public void doHandler(String password, CheckResult checkResult) throws Exception {
        char[] chPass = password.toCharArray();

        int specialCount = 0;

        for (char pass : chPass) {
            if (SPECIAL_CHAR.indexOf(pass) != -1) {
                ++specialCount;
            }
        }

        if (specialCount == 0) {
            checkResult.getConfirmInfo().add("#$%&'()*+等特殊字符");
        }

    }
}
